﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WMS_Order_Shelve.aspx.cs" Inherits="JYH.Web.MES.WMS.UI.WMS_Order_Shelve" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>调拨发料</title>
    <script type="text/javascript" >
        $(function () {
            $('#tt').datagrid({
                loadMsg: "正在接收数据...",
                iconCls: 'icon-reload',
                url: '',
                idField: 'TradeOrderID',
                autoRowHeight: false,
                fitColumns: false,
                scrollbarSize: 0,
                pageSize: 20,
                sortable: true,
                striped: false,      //隔行变色
                singleSelect: false, //是否单选
                pagination: true,   //分页控件  
                rownumbers: true,
                columns: [[
                    { field: 'TradeOrderID', checkbox: true },
                    { field: 'Opt', title: '操作', width: 230, align: 'center', formatter: ColumnOpt },
                    { field: 'TradeName', title: '单据类型' },
                    { field: 'TradeType', hidden: true },
                    { field: 'RState', hidden: true },
                    { field: 'RStateName', title: '记录状态', width: 80 },
                    { field: 'TradeOrderNO', title:'调拨单号', width: 140 },
                    { field: 'WarehouseName', title: '调出仓库' },
                    { field: 'ToWarehouseName', title: '调入仓库' },
                    { field: 'SourceOrderNO', title: '源单编号' },
                    { field: 'FromWarehouseID', hidden:true },
                    { field: 'ToWarehouseID', hidden: true },
                    { field: 'CreateTime', title: '制单日期', width: 140, sortable: true },
                    { field: 'CreateUser', title: '创建人员', width: 100 },
                    { field: 'ApproveDate', title: '审核日期', width: 140, sortable: true },
                    { field: 'ApproveUser', title: '审核人员', width: 100 }
                ]],
                rowStyler: function (index, row) {
                    if (row.RState === '1') {
                        // 审核状态（RState=1）：浅蓝色背景 + 深蓝色文字（适用于一般审核状态）
                        return 'background-color:#E3F2FD; color:#0D47A1;';
                    } else if (row.RState === '2') {
                        return 'background-color:#C8E6C9;'; //绿色背景
                    }
                },
                onLoadSuccess: function (data) {
                    $('#tt').datagrid("fillRows");
                    $('#tt').datagrid('resize');
                },
                onSortColumn: function (sort, order) {
                    $("#hSort").val(sort);
                    $("#hOrder").val(order);
                }
            });
            $(window).resize(function () {
                $('#tt').datagrid('resize');
            });
            $(".listmore").click(function () {
                $(".flistdis").toggle();
            });
        })
        function IndexOpen(rows) {
            OpenWindow("调拨发料维护", "WMS/UI/WMS_Order_ShelveEdit.aspx", 1200, 650, function () {
                loadLocal();
            });
        }
        //查询
        function loadLocal() {
            var TradeOrderNO = $("#txtTradeOrderNO").val();
           /* var PartnerNO = $("#txtPartnerNO").val();*/
            var BeginTime = $("#BeginTime").val();
            var EndTime = $("#EndTime").val();
            //排序字段
            var sort = $("#hSort").val();
            var order = $("#hOrder").val();
            $("#tt").datagrid({
                url: '/api/WMS/QueryWmsTradeOrderInfo',
                method: 'Get',
                queryParams: {
                    TradeOrderNO: TradeOrderNO,
                    BeginTime: BeginTime,
                    EndTime: EndTime,
                    sort: sort,
                    order: order,
                    TradeType:5
                },
                loadFilter: function (data) {
                    return JSON.parse(data);
                }
            });
            $('#tt').datagrid('clearSelections');
        }

        //删除
        function Delet() {
            var rows = $('#tt').datagrid('getSelections');
            if (rows.length < 1) {
                Alert("请选择后再删除！");
                return false;
            }
            for (var i = 0; i < rows.length; i++) {
                if (rows[i].RState != "0") {
                    Alert("单据:" + rows[i].TradeOrderNO + "不在新建状态,无法删除,请立即反审！");
                    return false;
                }
            }
            Confirm("确定要删除" + rows.length + "个收料单吗？", function () {
                var MateialInfo = fnSelectList('tt', rows);
                var url = '/api/WMS/DeleteWmsTradeOrderInfo';
                DataService.PostJson(url, MateialInfo, function (error, response) {
                    if (error) {
                        Notice("success!");
                    } else {
                        Alert(response);
                    }
                    loadLocal();
                })

            });
        }

        //审核
        function Check() {
            var rows = $('#tt').datagrid('getSelections');

            if (rows.Length<1) {
                Alert("请选择后再审核！");
                return false;
            }
            for (var i = 0; i < rows.length; i++) {
                if (rows[i].RState != "0") {
                    Alert("单据:" + rows[i].TradeOrderNO + "不在新建状态,无法审核！");
                    return false;
                }
            }
            Confirm("确定要审核吗？", function () {
                var MateialInfo = fnSelectList('tt', rows);
                var url = '/api/WMS/CheckWmsTradeOrderInfo';
                DataService.PostJson(url, MateialInfo, function (error, response) {
                    if (error) {
                        Notice("success");
                    } else {
                        Alert(response);
                    }
                    loadLocal();
                })

            });
        }
        //反审核
        function UpCheck() {
            var rows = $('#tt').datagrid('getSelections');
            if (rows.Length < 1) {
                Alert("请选择后再反审核！");
                return false;
            }
            for (var i = 0; i < rows.length; i++) {
                if (rows[i].RState != "1") {
                    Alert("单据:" + rows[i].TradeOrderNO + "不在审核状态,无法反审！");
                    return false;
                }
            }
            Confirm("确定要反审核吗？", function () {
                var MateialInfo = fnSelectList('tt', rows);
                var url = '/api/WMS/UpCheckWmsTradeOrderInfo';
                DataService.PostJson(url, MateialInfo, function (error, response) {
                    if (error) {
                        Notice("success");
                    } else {
                        Alert(response);
                    }
                    loadLocal();
                })

            });
        }
       
        function myformatter(date) {
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            var d = date.getDate();
            return y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d);
        }
        function myparser(s) {
            if (!s) return new Date();
            var ss = (s.split('-'));
            var y = parseInt(ss[0], 10);
            var m = parseInt(ss[1], 10);
            var d = parseInt(ss[2], 10);
            if (!isNaN(y) && !isNaN(m) && !isNaN(d)) {
                return new Date(y, m - 1, d);
            } else {
                return new Date();
            }
        }
        //根据状态改变值color
        //function setColumnForeColor(value, row, index) {

        //    if (value == '新建' || value == 'Editing') {
        //        //红色
        //        return '<span style="color:gray;">' + value + '</span>';
        //    }
        //    if (value == '已审核' || value == 'Approved') {
        //        //绿色
        //        return '<span style="color:Green;">' + value + '</span>';
        //    }
        //    if (value == '登账' || value == 'Account') {
        //        return '<span style="color:#07C160;">' + value + '</span>';
        //    }
        //    if (value == '删除' || value == 'Delete') {
        //        //灰色
        //        return '<span style="color:red;">' + value + '</span>';
        //    }
        //    return value;
        //}



        function ColumnOpt(value, row) {
            var temp = JSON.stringify(row);
            return "<a name='lock1' href='#' style='color:#a61c00' data-row='" + encodeURIComponent(temp) + "' onclick='Update(this);'>[Update]</a> &nbsp; | &nbsp;" +
                "<a name='lock2' href='#' style='color:#666666' data-row='" + encodeURIComponent(temp) + "' onclick='View(this);'>[Review]</a> &nbsp; | &nbsp;"+
                "<a name='lock3' href='#' style='color:#07C160' data-row='" + encodeURIComponent(temp) + "' onclick='Account(this);'>[Account]</a>";
        }
        //浏览
        function View(element) {
            var temp = decodeURIComponent(element.getAttribute('data-row'));
            var row = JSON.parse(temp);
            const params = encodeURIComponent(JSON.stringify(row));
            OpenWindow("调拨发料维护", "WMS/UI/WMS_Order_ShelveEdit.aspx?params=" + params + "&view=view", 1200, 650, function () {
                loadLocal();
            });
        }
        //修改
        function Update(element) {
            var temp = decodeURIComponent(element.getAttribute('data-row'));
            var row = JSON.parse(temp);
            if (row.RState != "0") {
                Notice("不在新建状态,无法修改！");
                return false;
            }
            const params = encodeURIComponent(JSON.stringify(row));
            OpenWindow("调拨发料维护", "WMS/UI/WMS_Order_ShelveEdit.aspx?params=" + params, 1200, 650, function () {
                loadLocal();
            });
        }
        //登账
        function Account(element) {
            var temp = decodeURIComponent(element.getAttribute('data-row'));
            var row = JSON.parse(temp);
            if (row.RState != "1") {
                Notice("不在审核状态,无法登账！");
                return false;
            }
            Confirm("确定要登账吗？", function () {
                var url = '/api/WMS/AccountWmsTradeOrderInfo';
                DataService.PostJson(url, row, function (error, response) {
                    if (error) {
                        Notice("success");
                    } else {
                        Alert(response);
                    }
                    loadLocal();
                })

            });
        }

      
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <%--排序隐藏值--%>
        <asp:HiddenField runat="server" ID="hSort" />
        <asp:HiddenField runat="server" ID="hOrder" />
        <div class="pagebox">
            <div class="cbox">
                <!--工具栏-->
                <div class="easyui-panel" style="padding: 15px; width: 100%;">
                    <div id="tb">
                        <ul class="flist">
                            <li>
                                <input class="easyui-textbox" type="text" id="txtTradeOrderNO" data-options="prompt:'请输入调拨单号'" style="width: 250px; height: 35px; line-height: 35px;" /></li>
                            <li>
                                <input class="easyui-datebox" labelposition="top" id="BeginTime" data-options="prompt:'收料日期',formatter:myformatter,parser:myparser" style="width: 250px; height: 35px;" />
                            </li>
                            <li>
                                <input class="easyui-datebox" labelposition="top" id="EndTime" data-options="prompt:'至',formatter:myformatter,parser:myparser" style="width: 250px; height: 35px;" />
                            </li>
                        </ul>
                        <div>
                            <a href="javascript:void(0)" class="easyui-linkbutton c1" onclick="loadLocal()" data-options="iconCls:'icon-sousuo',selected:true">查询</a>
                            <a href="#" class="easyui-linkbutton c4" data-options="iconCls:'icon-tianjia'" onclick="IndexOpen('')">新增</a>
                            <a href="#" class="easyui-linkbutton c8" data-options="iconCls:'icon-xiangmu'" onclick="Check()">审核</a>
                            <a href="#" class="easyui-linkbutton c6" data-options="iconCls:'icon-Components'" onclick="UpCheck()">反审</a>
                             <a href="#" class="easyui-linkbutton c2" data-options="iconCls:'icon-buchongiconsvg13'" onclick="Delet()">删除</a>

                        </div>

                    </div>
                </div>
            </div>
            <div class="cbox">
                <!--查询结果清单-->
                <table id="tt" title="调拨单列表">
                </table>
            </div>
        </div>
    </form>
</body>
</html>
